<?php
class SubpageCaching
{
    const IDC               = 'subpage';
    const SHARDING_ID       = 0;
    const CURRENT_ZONE_NAME = ZONE_ENV;
    /**
     * Memcache key
     */
    const SUBPAGE_ARTICLE_DETAIL        = "subpage_article_detail";
    const SUBPAGE_LIST_COMMENT_ARTICLE  = "subpage_list_comment_article";

    /**
     * Instance
     */
    protected static $_instance = null;

    /**
     * Constructor of class
     */
    protected function  __construct()
    {

    }

    /**
     * Get singleton instance
     */
    public final static function getInstance()
    {
        //Check instance
        if ( is_null(self::$_instance) )
        {
            self::$_instance    = new self();
        }//end if

        //Return instance
        return self::$_instance;
    }

    /**
     * Get object key by type
     */
    public function getObjKeyByType($type, $params)
    {       
        $keyCaching = '';
        switch ( $type )
        {
            case self::SUBPAGE_ARTICLE_DETAIL:
                $keyCaching = $this->makeRedisKey(Fpt_Global::getPrefixCaching(self::SUBPAGE_ARTICLE_DETAIL), $params);                
                break;
            case self::SUBPAGE_LIST_COMMENT_ARTICLE:
                $keyCaching = $this->makeRedisKey(Fpt_Global::getPrefixCaching(self::SUBPAGE_LIST_COMMENT_ARTICLE), $params);
                break;
            default:
                break;
        }//end switch

        //Return
        return $keyCaching;
    }

    /**
     * Make redis key
     */
    public function makeRedisKey($format, $args)
    {       
        if ( !is_array($args) )
        {
            //Return
            return sprintf($format, $args);
        }//end if

        //Merge param
        $format = array($format);
        $args   = array_merge($format, $args);

        //Return
        return call_user_func_array("sprintf", $args);
    }
}